package com.nbsaas.boot.controller.site;

import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.site.api.apis.FeedBackApi;
import com.nbsaas.boot.site.api.domain.request.FeedBackRequest;
import com.nbsaas.boot.site.api.domain.request.FeedBackSearch;
import com.nbsaas.boot.site.api.domain.response.FeedBackResponse;
import com.nbsaas.boot.site.api.domain.simple.FeedBackSimple;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/feedBack")
public class FeedBackController {


    @Resource
    private FeedBackApi feedBackApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("feedBack")
    @PostMapping("/search")
    public PageResponse<FeedBackSimple> search(@RequestBody FeedBackSearch request) {
        return feedBackApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("feedBack")
    @PostMapping("/list")
    public ListResponse<FeedBackSimple> list(@RequestBody FeedBackSearch request) {
        return feedBackApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("feedBack")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<FeedBackResponse> create(@RequestBody @Validated(AddOperator.class) FeedBackRequest request) {
        return feedBackApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("feedBack")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<FeedBackResponse> update(@RequestBody @Validated(UpdateOperator.class) FeedBackRequest request) {
        return feedBackApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("feedBack")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) FeedBackRequest request) {
        return feedBackApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("feedBack")
    @PostMapping("/view")
    public ResponseObject<FeedBackResponse> view(@RequestBody @Validated(ViewOperator.class) FeedBackRequest request) {
        return feedBackApi.view(request);
    }
}